﻿using System;
using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Windows;
using Silvermoon.Windows.Styles;
using Silvermoon.OpenGL;
using Silvermoon.Images;
using Silvermoon.Shapes;
using Silvermoon.UI;
using System.Drawing;

namespace Testing.Pages
{
    /// <summary>
    /// Same as ListViewPage but shows 7 date items in one single row and adds some style to the ListViewController.
    /// This example illustrates how to use ListViewController and styles.
    /// </summary>
    public class ColumnListViewPage : ListViewPage
    {
        private static VisualStateManager emptyManager = new VisualStateManager();
        protected override void InitializePage()
        {
            base.InitializePage();
            SetTransition(350, TransitionMask.RotateLeftOut, TransitionMask.RotateLeftOut);
            Title = "LISTVIEW WITH COLUMNS";

            listView.AlwaysShowGroupHeader = false;
            listViewController.ItemsPerRow = 7;
            listViewController.PickerTileSize = new Size(208, 80);
            listViewController.GroupButtonSize = new Size(480 - 24, 80);

            listViewController.GroupStyle = new Style
            {
                Margin = new Margin(0, 0, ScrollViewer.ScrollbarWidth + 1, 16),
                Background = PhoneColors.White,
                //                Background = new BackgroundShape { Texture = ImagePool.Rounded, Style = RenderStyle.Edged, Color = PhoneColors.White },
                Color = PhoneColors.White
            };
            listViewController.GroupButtonStyle = new Style
            {
                Name = "MyStyle",
                //Background = new BackgroundShape { Texture = ImagePool.TopRounded, Style = RenderStyle.Edged },
                Background = PhoneColors.Orange,
                Chrome = Shape.Empty,
                Margin = new Margin(0),
                Color = PhoneColors.Orange,
                StateManager = emptyManager
            };

            listViewController.ItemStyle = new TextItemStyle { Font = FontSprite.Regular, TextColor = PhoneColors.Black };
        }

        protected override void OnUpdateItem(object sender, ItemControlGeneratorEventArgs<TextItem> e)
        {
            var item = e.Item;
            DateTime date = (DateTime)item.DataValue;
            item.Text = date.Day.ToString();
            item.TextColor = date.DayOfWeek == DayOfWeek.Sunday ? PhoneColors.Orange : PhoneColors.Black;
        }

    }
}
